<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title>登录</title>
    <jsp:include page="common.jsp"></jsp:include>
</head>
<body>
<div class="bg"></div>
<div class="container">
    <div class="line bouncein">
        <div class="xs6 xm4 xs3-move xm4-move">
            <div style="height:150px;"></div>
            <div class="media media-y margin-big-bottom">
            </div>
            <form id="loginForm" action="#" method="post" onsubmit="return false;">
                <div class="panel loginbox">
                    <div class="text-center margin-big padding-big-top"><h1>后台管理中心</h1></div>
                    <div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input type="text" class="input input-big" name="name" placeholder="登录账号" data-validate="required:请填写账号" />
                                <span class="icon icon-user margin-small"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="field field-icon-right">
                                <input type="password" class="input input-big" name="password" placeholder="登录密码" data-validate="required:请填写密码" />
                                <span class="icon icon-key margin-small"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="field">
                                <input type="text" class="input input-big" name="code" placeholder="填写右侧的验证码" data-validate="required:请填写右侧的验证码" />
                                <img src="${ctx}/code.do" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">
                            </div>
                            <p onclick="refreshCode()">看不清，请点击这里</p>
                        </div>
                    </div>
                    <div style="padding:30px;"><input type="submit" id="loginBtn" class="button button-block bg-main text-big input-big" value="登录"></div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function refreshCode() {
        var t=new Date();
        $(".passcode").attr("src","${ctx}/code.do?"+t);

    }

    $("#loginBtn").click(function () {
        //获取输入框  的name属性为name  的值
        /*var name=$("input[name='name']").val();
        var password=$("input[name='password']").val();
        var code=$("input[name='code']").val();*/
        //表单序列化 将表单中所有数据按照name属性为key, value位置
        //打包为json格式
        var mydata=$("#loginForm").serialize();
        $.post("${ctx}/manage/login.do",mydata,function (data) {
            if (data.state==0){//登录成功
                window.location.href="${ctx}/manage/index.do";
            }else{
                refreshCode();//刷新验证码
                alert(data.msg)
            }
        },"json")

    })
</script>

</body>
</html>